#include "StdAfx.h"
#include "MemoryMap.h"

CMemoryMap::CMemoryMap(void)
{
	m_hProcess = NULL;
}

CMemoryMap::~CMemoryMap(void)
{
	Destroy();
}

void CMemoryMap::Destroy() {
	if(m_hProcess) {
		::CloseHandle(m_hProcess);
		m_hProcess = NULL;
	}
}

bool CMemoryMap::Init(DWORD pid) {
	Destroy();

	m_hProcess = ::OpenProcess(PROCESS_QUERY_INFORMATION, FALSE, pid);
	if(!m_hProcess) return false;

	m_pAddress = NULL;
	return true;
}

MEMORY_BASIC_INFORMATION* CMemoryMap::GetNext() {
	DWORD count = ::VirtualQueryEx(m_hProcess, m_pAddress, &m_Info, sizeof(m_Info));
	if(count == 0) return NULL;

	m_pAddress += m_Info.RegionSize;
	return &m_Info;
}

